package com.juzi.operator;

public class OperatorDemo8 {
    public static void main(String[] args) {
        //目标：学会使用三元运算符，理解其流程
        System.out.println("三元运算符介绍");
        System.out.println("=============================");
        System.out.println("格式：条件表达式？值1:值2;");
        System.out.println("执行流程：首先计算关系表达式的值，如果为true，返回值1，反之，返回值2");
        System.out.println("---------------------------");

        double score = 98;
        String rs = score >= 60 ? "考试通过" : "挂科";
        System.out.println(rs);

        //需求：从2个整数中找到较大值
        int a = 10;
        int b = 2000;
        int max = a > b ? a : b;
        System.out.println(max);

        System.out.println("--------------------------------------------");
        int i = 10;
        int j = 30;
        int k = 50;
        //1、找出2个整数较大值
        int temp = i > j ? i : j;
        //2、用临时变量与第三个变量继续比较
        int rsMax = temp > k ? temp : k;
        System.out.println(rsMax);

        System.out.println("--------------拓展----------------");
        int rsMax1 = i > j ? i > k ? i : k : j > k ? j : k;
        System.out.println(rsMax1);
    }
}
